home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-07-13 | 3.0 KB | 88 lines |
- /*
- * Copyright (c) 1995-1997 Sun Microsystems, Inc. All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software
- * and its documentation for NON-COMMERCIAL purposes and without
- * fee is hereby granted provided that this copyright notice
- * appears in all copies. Please refer to the file "copyright.html"
- * for further important copyright and licensing information.
- *
- * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
- * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
- * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
- */
- import java.awt.*;
-
- public class GridBagWindow extends Frame {
- private boolean inAnApplet = true;
-
- protected void makebutton(String name,
- GridBagLayout gridbag,
- GridBagConstraints c) {
- Button button = new Button(name);
- gridbag.setConstraints(button, c);
- add(button);
- }
-
- public GridBagWindow() {
- GridBagLayout gridbag = new GridBagLayout();
- GridBagConstraints c = new GridBagConstraints();
-
- setFont(new Font("Helvetica", Font.PLAIN, 14));
- setLayout(gridbag);
-
- c.fill = GridBagConstraints.BOTH;
- c.weightx = 1.0;
- makebutton("Button1", gridbag, c);
- makebutton("Button2", gridbag, c);
- makebutton("Button3", gridbag, c);
-
- c.gridwidth = GridBagConstraints.REMAINDER; //end of row
- makebutton("Button4", gridbag, c);
-
- c.weightx = 0.0; //reset to the default
- makebutton("Button5", gridbag, c); //another row
-
- c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last in row
- makebutton("Button6", gridbag, c);
-
- c.gridwidth = GridBagConstraints.REMAINDER; //end of row
- makebutton("Button7", gridbag, c);
-
- c.gridwidth = 1; //reset to the default
- c.gridheight = 2;
- c.weighty = 1.0;
- makebutton("Button8", gridbag, c);
-
- c.weighty = 0.0; //reset to the default
- c.gridwidth = GridBagConstraints.REMAINDER; //end of row
- c.gridheight = 1; //reset to the default
- makebutton("Button9", gridbag, c);
- makebutton("Button10", gridbag, c);
- }
-
- public boolean handleEvent(Event e) {
- if (e.id == Event.WINDOW_DESTROY) {
- if (inAnApplet) {
- dispose();
- return true;
- } else {
- System.exit(0);
- }
- }
- return super.handleEvent(e);
- }
-
- public static void main(String args[]) {
- GridBagWindow window = new GridBagWindow();
- window.inAnApplet = false;
-
- window.setTitle("GridBagWindow Application");
- window.pack();
- window.show();
- }
- }
-